package com.l2jserver.gameserver.network.serverpackets;

import java.util.Map;
import java.util.Map.Entry;

import com.l2jserver.gameserver.datatables.PrimeShopTable;
import com.l2jserver.gameserver.datatables.PrimeShopTable.PrimeShopItem;

/**
 * @author fissban
 */
public class ExBrProductList extends L2GameServerPacket
{
	private final Map<Integer, PrimeShopItem> primeList;
	
	public ExBrProductList()
	{
		primeList = PrimeShopTable.getInstance().getPrimeItems();
		
	}
	
	@Override
	protected void writeImpl()
	{
		writeC(0xFE);
		writeH(0xD6);
		writeD(primeList.size());
		
		for (Entry<Integer, PrimeShopItem> entrySet : primeList.entrySet())
		{
			PrimeShopItem item = entrySet.getValue();
			if ((System.currentTimeMillis() >= item.sale_start_date()) && (System.currentTimeMillis() <= item.sale_end_date()))
			{
				int brId = entrySet.getKey().intValue();
				
				writeD(brId); // product id
				writeH(item.getPrimeItemCat()); // category 1 - enchant 2 - supplies 3 - decoration 4 - package 5 - other
				writeD(item.getPrimeItemPrice()); // points
				writeD(item.getPrimeType());// show tab 2-th group - 1 ?????????? ?????? ??? ???? 1 - event 2 - best 3 - event & best
				writeD((int) (item.sale_start_date() / 1000)); // start sale
				writeD((int) (item.sale_end_date() / 1000)); // end sale
				writeC(1); // day week... necesita revisarse (0x00)
				writeC(item.getStartHour()); // start hour
				writeC(item.getStartMin()); // start min
				writeC(item.getEndHour()); // end hour
				writeC(item.getEndMin()); // end min
				
				writeD(PrimeShopTable.getInstance().getActualStock(brId)); // current stock
				writeD(PrimeShopTable.getInstance().getMaxStock(brId)); // max stock
			}
		}
	}
}